package com.oot2d.world;

import org.newdawn.slick.geom.Polygon;

public class Tile {
    private int x, y;
    public int collision;
    public Polygon bounds;

    public Tile(int tx, int ty)
    {
        x = tx;
        y = ty;
    }

    public Tile(int tx, int ty, int c)
    {
        x = tx;
        y = ty;
        collision = c;

        //Create a collision poly
        switch (c) {
            //Full tile
            case 0:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //All but bottom-right cell
            case 1:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //All but bottom-left cell
            case 2:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        x * 16.0f, (y * 16.0f) + 8.0f
                });
                break;

            //All but top-right cell
            case 3:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //All but top-left cell
            case 4:
                bounds = new Polygon(new float[]{
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f
                });
                break;

            //Diagonal top-left
            case 5:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Diagonal top-right
            case 6:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Diagonal bottom-left
            case 7:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Diagonal bottom-right
            case 8:
                bounds = new Polygon(new float[]{
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Left half
            case 9:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Top half
            case 10:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        x * 16.0f, (y * 16.0f) + 8.0f
                });
                break;

            //Right half
            case 11:
                bounds = new Polygon(new float[]{
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Bottom half
            case 12:
                bounds = new Polygon(new float[]{
                        x * 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Top-left cell
            case 13:
                bounds = new Polygon(new float[]{
                        x * 16.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        x * 16.0f, (y * 16.0f) + 8.0f
                });
                break;

            //Bottom-left cell
            case 14:
                bounds = new Polygon(new float[]{
                        x * 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f,
                        x * 16.0f, (y * 16.0f) + 16.0f
                });
                break;

            //Top-right cell
            case 15:
                bounds = new Polygon(new float[]{
                        (x * 16.0f) + 8.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, y * 16.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f
                });
                break;

            //Bottom-right cell
            case 16:
                bounds = new Polygon(new float[]{
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 8.0f,
                        (x * 16.0f) + 16.0f, (y * 16.0f) + 16.0f,
                        (x * 16.0f) + 8.0f, (y * 16.0f) + 16.0f
                });
                break;
        }
    }

    public void draw()
    {

    }

    public Polygon getBounds()
    {
        return bounds;
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }

    public float getWX()
    {
        return x * 16.0f;
    }

    public float getWY()
    {
        return y * 16.0f;
    }
}
